package com.nit.tools;

import javax.annotation.CheckForNull;
import java.util.Collection;
import java.util.Objects;

/**
 * 校验工具
 *
 * @Auth: 逆天开源-逍遥哥哥
 * @Date: 2023-07-11
 */
public class NitAssertTools {

    public static void checkArgumentNull(Object obj, @CheckForNull Object errorMessage) {
        if (Objects.isNull(obj)) {
            throw new IllegalArgumentException(String.valueOf(errorMessage));
        }
        if (obj instanceof String) {
            if (NitStringTools.isBlank((String) obj)) {
                throw new IllegalArgumentException(String.valueOf(errorMessage));
            }
        }
        if (obj instanceof Collection) {
            if (((Collection<?>) obj).size() == 0) {
                throw new IllegalArgumentException(String.valueOf(errorMessage));
            }
        }
    }

    public static void checkArgument(boolean expression) {
        if (!expression) {
            throw new IllegalArgumentException();
        }
    }

    public static void checkArgument(boolean expression, @CheckForNull Object errorMessage) {
        if (!expression) {
            throw new IllegalArgumentException(String.valueOf(errorMessage));
        }
    }
}
